// https://vitejs.dev/config/
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
export default defineConfig(({ command, mode }) => {
  //获取各种环境下的对应的变量
  let env = loadEnv(mode, process.cwd());
  console.log('evn',env)
  return {
    publicPath: '/',
    plugins: [vue()],
    resolve: {
      alias: {
        "@": path.resolve("./src") // 相对路径别名配置，使用 @ 代替 src
      }
    },
    //scss全局变量一个配置
    css: {},
    //代理跨域
    server: {
      open: true,
      proxy: {
        '/api/list': {
          target: "http://localhost:3000",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/list/, '')
        },
        '/api/formList': {
          target: "http://localhost:3000",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/formList/, '')
        },
      }
    }
  }
})



// import { defineConfig } from 'vite'
// import vue from '@vitejs/plugin-vue'
//
// // https://vitejs.dev/config/
// export default defineConfig({
//   plugins: [vue()],
//   server: {
//     proxy: {
//       // 选项写法
//       '/api': {
//         target: 'http://localhost:3000',  // 接口地址
//         changeOrigin: true,
//         rewrite: (path) => path.replace(/^\/api/, '')
//       },
//     }
//   }
// })
